import { SpriteFrame } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { App } from '../../App';
import { find } from 'cc';
import { Sprite } from 'cc';
import { tween } from 'cc';
import { Vec3 } from 'cc';
import { UIOpacity } from 'cc';
import GameUtils2 from './mode2/GameUtils2';
import UtilTool from '../../tools/UtilTool';
const { ccclass, property } = _decorator;

// 连杆动画
@ccclass('ComboNode')
export class ComboNode extends Component {

    start() {
        
    }

    // 连杠
    showCombo(combo : number) {

        UtilTool.printLog("showCombo", combo);

        let sp = App.Scene.getRes("images/combo")["combo"+combo]
        // let sp = GameUtils2.getRes("images/combo")["combo"+combo]
        let img = find("img", this.node)

        UtilTool.printLog("showCombo", sp);

        let sprite : Sprite = img.getComponent(Sprite)
        sprite.spriteFrame = sp
        
        this.runAction()

    }

    // 一杆清台
    showAllOneClear() {
        let sp = App.Scene.getRes("images/combo")["all_one"]
        let img = find("img", this.node)
        let sprite : Sprite = img.getComponent(Sprite)
        sprite.spriteFrame = sp

        this.runAction()
    }

    // 决战时刻
    showDecisiveMoment() {
        let sp = App.Scene.getRes("images/combo")["decisiveMoment"]
        let img = find("img", this.node)
        let sprite : Sprite = img.getComponent(Sprite)
        sprite.spriteFrame = sp

        this.runAction()
    }

    runAction() {

        let img = find("img", this.node)
        let sprite : Sprite = img.getComponent(Sprite)

        this.node.setScale(0.4,0.4,1);
        this.node.setPosition(-50, 0, 0)
        tween()
            .target(this.node)
            .to(0.07,{ scale: new Vec3(1.2, 1.2, 1) })
            .to(0.1,{ scale: new Vec3(0.6, 0.6, 1) })
            .to(0.1,{ scale: new Vec3(1.1, 1.1, 1) })
            .to(0.05,{ scale: new Vec3(0.8, 0.8, 1) })
            .to(0.05,{ scale: new Vec3(1.0, 1.0, 1) })
            .to(0.05,{ scale: new Vec3(0.9, 0.9, 1) })
            .to(0.05,{ scale: new Vec3(1.0, 1.0, 1) })

            .delay(1.0)
            .by(0.4, { position: new Vec3(0, 160, 0) })
            .call(() => {
                this.node.destroy();
            })
            .start()
            
        tween(img.getComponent(UIOpacity))
            .delay(1.4)
            .to(0.4, { opacity: 0 }).start()
    }

}

